const {
  $util,
} = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    searchlist: [],
    issearch: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    this.loadInfo();
  },
  loadInfo() {
    $util.request({
      url: 'entry/wxapp/partyman.home.getorganlist',
      data: {},
      success: (res) => {
        this.setData({
          list: res.data,
        });
      },
    });
  },
  getIpval(e) {
    this.setData({
      val: e.detail.value,
    });
  },
  getsearch() {
    const {
      list,
      val,
    } = this.data;
    const searchlist = [];
    for (const i of list) {
      if (i.name.includes(val)) {
        searchlist.push(i);
      }
    }
    this.setData({
      issearch: true,
      searchlist,
    });
  },
  getlocation(e) {
    const { id } = e.currentTarget.dataset;
    const { list } = this.data;
    const page = getCurrentPages();
    const prepage = page[page.length - 2];
    let markerIdx = 0;
    for (const i in list) {
      if (list[i].id === id) {
        markerIdx = i;
      }
    }
    wx.navigateBack({
      success: () => {
        prepage.setData({
          lat: list[markerIdx].latitude,
          lng: list[markerIdx].longitude,
          defaultLat: -1,
          defaultLng: -1,
          isshowinfo: true,
          markerIdx,
        });
      },
    });
  },
});
